package atm.com.service.stream;

import atm.com.mapper.StreamMapper;
import atm.com.pojo.Bankcard;
import atm.com.pojo.Stream;
import atm.com.util.CommonUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;


/**
 * StreamServiceImpl class
 * @author di zhang
 * @date 2021/8/24
 */
@Service
public class StreamServiceImpl implements StreamServiceInf {
    @Autowired
    private StreamMapper streamMapper;
    @Override
    public List<Stream> ListStreamByBankCardId(Bankcard bankCard) {
        CommonUtil commonUtil=new CommonUtil();
        QueryWrapper<Stream> queryWrapper= new QueryWrapper<>();
        Timestamp tm = new Timestamp(System.currentTimeMillis()-1000 * 60 * 60 * 24 * 7);
        //查看一周以内的流水
        queryWrapper.lambda().eq(Stream :: getBankcardId,bankCard.getBankcardId()).between(Stream::getGmtCreate,tm,new Date());
           return streamMapper.selectList(queryWrapper);
    }

    @Override
    public void InsertStream(Stream stream) {
        streamMapper.insert(stream);
    }
}
